package donjuan;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
//该面板用于展示添加、删除、查找、更新的主界面，通过点击对应按钮实现跳转
public class Window_manage extends JPanel implements ActionListener {
  JLabel show = new JLabel("信息管理");
  
  JButton add = new JButton("添加");
  
  JButton del = new JButton("删除");
  
  JButton ser = new JButton("查找");
  
  JButton fre = new JButton("更新");
  
  String[] data = new String[5];
  
  JTextField[] cin = new JTextField[5];
  
  ImageIcon imageIcon = new ImageIcon("src/qingque.png"); 
 
  Image image = imageIcon.getImage();

  JLabel label = new JLabel(imageIcon);
  
  JButton refresh=new JButton(imageIcon);

  public static int status = 0;
  
  Window_manage() {
    for (int i = 0; i < 5; ) {
      this.data[i] = "";
      i++;
    } 
    setVisible(true);
    setBounds(50, 50, 300, 300);
    setName("请输入信息");
    setLayout(new BorderLayout());
    init();
  }
  
  void init() {
	label.setBounds(50, 30, 200, 150);  
    this.add.addActionListener(this);
    this.del.addActionListener(this);
    this.ser.addActionListener(this);
    this.fre.addActionListener(this);
    this.refresh.addActionListener(this);
    add.setBorder(BorderFactory.createRaisedBevelBorder());
    add.setFont(new Font("华文行楷",2,15));
    del.setBorder(BorderFactory.createRaisedBevelBorder());
    del.setFont(new Font("华文行楷",2,15));
    ser.setBorder(BorderFactory.createRaisedBevelBorder());
    ser.setFont(new Font("华文行楷",2,15));
    fre.setBorder(BorderFactory.createRaisedBevelBorder());
    fre.setFont(new Font("华文行楷",2,15));
    add(this.add,BorderLayout.WEST);
    add(this.del,BorderLayout.EAST);
    add(this.fre,BorderLayout.SOUTH);
    add(this.ser,BorderLayout.NORTH);
    add(refresh,BorderLayout.CENTER);
  }
  
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.add) {
      status = 0;
      Window_main.mode = 5;
      Window_Login.change_mode();
      Window_main.jump();
    } else if (e.getSource() == this.del) {
      status = 1;
     this.show.setVisible(false);
      Dialog_mode dialog_mode = new Dialog_mode();
    } else if (e.getSource() == this.fre) {
      status = 2;
      this.show.setVisible(false);
      Dialog_mode dialog_mode = new Dialog_mode();
    } else if (e.getSource() == this.ser) {
      status = 3;
      this.show.setVisible(false);
      Dialog_mode dialog_mode = new Dialog_mode();
    } else if (e.getSource() == this.refresh) {
    	 if (Message.con != null)
    	  try {  Message.con.close(); } 
    	 	catch (SQLException e1) {System.exit(-1);}     
    	 Message.judgement=true;
    	 Message.Link_start=false;
    	 Message.read = new ArrayList<>(3);
    	 Readin.resetdata();
    	 AutoRegister pass=new AutoRegister();
      } 
  }
}
